package com.ky.manage.activity;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.ky.manage.BaseApplication;
import com.ky.manage.BuildConfig;
import com.ky.manage.R;
import com.ky.manage.activity.web.X5WebActivity;
import com.ky.manage.base.BaseActivity;
import com.ky.manage.constant.OverallData;
import com.ky.manage.model.LoginUserInfo;
import com.ky.manage.utils.Utils;
import com.ky.manage.utils.ZyUtils;
import com.ky.manage.utils.http.BusinessHttpReqUtils;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class SettingActivity extends BaseActivity {
    private TextView mLogoutTv;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initView() {
        findTextView(R.id.page_title_tv, "设置");
        findView(R.id.back_iv, v -> {
            finish();
        });
        findView(R.id.person_info_tv, v -> {
            //已登录跳转个人信息页、未登录跳转登录页
            if (BaseApplication.isValidLogin(this, true)) {
                toActivity(new Intent(this, PersonalInfoActivity.class));
            }
        });
        findView(R.id.privacy_arrow_rl, v -> {
            if (ZyUtils.getInstance().isNetConnected()) {
                X5WebActivity.toWebActivity(this, "隐私条款",
                        "https://www.keyifazhan.com/permission_statement.html");
            }
        });
        findView(R.id.about_us_arrow_rl, v -> {
            toActivity(new Intent(mCurActivity, AboutUsActivity.class));
        });
        findTextView(R.id.version_info_tv, BuildConfig.VERSION_NAME);
        findTextView(R.id.customer_service_info_tv, OverallData.CUSTOMER_SERVICE_PHONE, v -> {
            Utils.callPhone(this, OverallData.CUSTOMER_SERVICE_PHONE);
        });

        mLogoutTv = findView(R.id.logout_tv, v -> {
            //退出登录
            BusinessHttpReqUtils.getInstance().logout();
        });
        mLogoutTv.setVisibility(BaseApplication.isValidLogin() ? View.VISIBLE : View.GONE);
    }

    @Override
    protected void initData() {

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onLoginStateChange(LoginUserInfo event) {
        if (null == event) {
            return;
        }
        mLogoutTv.setVisibility(event.isLogin ? View.VISIBLE : View.GONE);
    }
}